{{template "admin/header.html"}}
<title>新增设置 - GPRESS</title>
{{template "admin/bodystart.html"}}

<section class="section">
	<input type="hidden" id="basePath" value="{{basePath}}">

	<div class="container">
		<div class="table-content">
			<!-- is-6-desktop is-6-tablet -->
			<div class="column">
				<form id="gpress-form" action="{{basePath}}admin/{{.UrlPathParam}}/save" method="POST">
					<ul class="save-ul">
						<li>
							<div class="left">
								基础路径
							</div>
							<div class="right">
								<input class="input" type="text" name="basePath" id="basePath">
							</div>
						</li>
						<li>
							<div class="left">
								jwt密钥
							</div>
							<div class="right">
								<input class="input" type="text" name="jwtSecret" id="jwtSecret">
							</div>
						</li>
						<li>
							<div class="left">
								jwt的key
							</div>
							<div class="right">
								<input class="input" type="text" name="jwttokenKey" id="jwttokenKey">
							</div>
						</li>
						<li>
							<div class="left">
								服务器ip:端口
							</div>
							<div class="right">
								<input class="input" type="text" name="serverPort" id="serverPort">
							</div>
						</li>
						<li>
							<div class="left">
								主题
							</div>
							<div class="right">
								<input class="input" type="text" name="theme" id="theme">
							</div>
						</li>
						<li>
							<div class="left">
								超时时间
							</div>
							<div class="right">
								<input class="input" type="number" name="timeout" id="timeout">
							</div>
						</li>
						
					</ul>
					<div class="field is-grouped" style="padding-left: 190px;">
						<div class="control">
							<button type="submit" class="button is-primary">提交</button>
						</div>
						<div class="control">
							<button type="reset" class="button is-info is-light">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</section>

<script>
	// 保存提交
	const form = document.querySelector('#gpress-form')
	form.addEventListener('submit', async event => {
		event.preventDefault()
		const formData = new FormData(form)
		const jsonObject = {}
		for (const [key, value] of formData.entries()) {
			const fieldType = document.querySelector(key)
							jsonObject[key] = value
		}
		jsonObject.sortNo = jsonObject.sortNo-0
		jsonObject.status = jsonObject.status-0

		const response = await fetch(form.action, {
			method: form.method,
			body: JSON.stringify(jsonObject),
			headers: { 'Content-Type': 'application/json' }
		})
		let res = await response.json()
		if (res.statusCode == 1) {
			$.confirm({
				useBootstrap: false,
				boxWidth: '400px',
				title: '提示',
				content: '保存成功！',
				type: 'green',
				buttons: {
					'确定': function() {
						window.location.href = '{{basePath}}admin/{{.UrlPathParam}}/list'
					}
				}
			})
		}
	})
</script>


{{template "admin/bodyend.html"}}
